"""
IAPF协议热加载引擎
"""

import requests
from cachetools import TTLCache

class ProtocolLoader:
    def __init__(self):
        self.cache = TTLCache(maxsize=100, ttl=3600)
        
    def load(self, url: str) -> dict:
        """加载远程协议"""
        if cached := self.cache.get(url):
            return cached
            
        resp = requests.get(url, timeout=10)
        resp.raise_for_status()
        
        protocol = {
            'content': resp.text,
            'metadata': {
                'etag': resp.headers.get('ETag'),
                'last_modified': resp.headers.get('Last-Modified')
            }
        }
        self.cache[url] = protocol
        return protocol